package org.jeecg.modules.tls.oes.subject.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.tls.oes.subject.entity.OesSubject;
import org.jeecg.modules.tls.oes.subject.mapper.OesSubjectMapper;
import org.jeecg.modules.tls.oes.subject.service.IOesSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: oes_subject
 * @Author: jeecg-boot
 * @Date:   2022-11-28
 * @Version: V1.0
 */
@Service
public class OesSubjectServiceImpl extends ServiceImpl<OesSubjectMapper, OesSubject> implements IOesSubjectService {

    @Autowired
    OesSubjectMapper subjectDao;

    @Override
    public IPage<OesSubject> getSubjectPage(Integer level, Integer pageIndex, Integer pageSize) {
        QueryWrapper<OesSubject> subjectQueryWrapper = new QueryWrapper<>();
        if(level!=null){
            subjectQueryWrapper.eq("level",level);
        }
        //subjectQueryWrapper.orderByAsc("item_order");
        Page<OesSubject> page = new Page<>(pageIndex,pageSize);

        IPage<OesSubject> iPage = this.subjectDao.selectPage(page,subjectQueryWrapper);

        return iPage;
    }

    @Override
    public Boolean modifySubject(OesSubject subject) {
        OesSubject subject1 = new OesSubject();
        subject1.setId(subject.getId());
        subject1.setLevel(subject.getLevel());
        subject1.setLevelName(subject.getLevelName());

        return this.subjectDao.updateById(subject1)>0;
    }

    @Override
    public Boolean deleteSubject(Integer id) {

        return subjectDao.deleteById(id)>0;
    }

    @Override
    public Boolean addSubject(OesSubject subject) {
        subject.setDeleted(0);

        return this.subjectDao.insert(subject)>0;
    }

    @Override
    public Integer getSubjectLevel(Integer id) {
        OesSubject subject = this.subjectDao.selectById(id);

        return subject.getLevel();
    }

    @Override
    public OesSubject getSubjectById(Integer id) {
        return subjectDao.selectById(id);
    }

//    @Override
//    public List<TSubject> getSubjects() {
//        User user = UserUtil.getUser();
//        QueryWrapper<Subject> subjectQueryWrapper = new QueryWrapper<>();
//        subjectQueryWrapper.eq("level",user.getUserLevel());
//
//        return subjectDao.selectList(subjectQueryWrapper);
//    }

    @Override
    public List<OesSubject> getSubjectsByLevel(Integer level) {
        QueryWrapper<OesSubject> subjectQueryWrapper = new QueryWrapper<>();
        subjectQueryWrapper.eq("level",level);

        return subjectDao.selectList(subjectQueryWrapper);
    }
}
